<?php
namespace app\controller;

use app\BaseController;

class Index extends BaseController
{
    protected $middleware = ['checkAdmin'];

    protected function initialize()
    {
        parent::initialize();
        $this->logic = new \app\logic\Index();
    }

    // layout
    public function index()
    {
        return view("", [
            'user' => (new \app\model\User())->getOneInfoByWhere(['id' => session('user')['id'] ?? 0], 'id,username,last_time,last_ip')
        ]);
    }

    // 首页
    public function home()
    {
        return view("", [
            'info'  => $this->logic->indexData()
        ]);
    }

    // 菜单配置
    public function menu()
    {
        return json([
            [
                "id"    => 5,
                "pid"   => 0,
                "title" => "配置管理",
                "icon"  => "layui-icon layui-icon-set",
                "href"  => (string) url('config/index'),
                "type"  => 1,
            ],[
                "id"    => 6,
                "pid"   => 0,
                "title" => "文件管理",
                "icon"  => "layui-icon layui-icon-file",
                "href"  => (string) url('upload/index'),
                "type"  => 1,
            ], [
                "id"        => 2,
                "pid"       => 0,
                "title"     => "软件管理",
                "icon"      => "layui-icon layui-icon-app",
                "href"      => "",
                "type"      => 0,
                "children"  => [
                    [
                        "id"    => 3,
                        "pid"   => 2,
                        "title" => "软件列表",
                        "icon"  => "",
                        "href"  => (string) url('software/index'),
                        "type"  => 1,
                    ],
                    [
                        "id"    => 4,
                        "pid"   => 2,
                        "title" => "版本列表",
                        "icon"  => "",
                        "href"  => (string) url('version/index'),
                        "type"  => 1,
                    ],
                ]
            ]
        ]);
    }

    // 返回 layout.default 页面配置
    public function layoutConfig()
    {
        return json(config('layoutconfig'));
    }
}
